+ | addition |
- | subtraction |
* | multiplication |
/ | division |
Each of these operators requires two operands. When two operands for an arithmetic expression are of different number classes, one operand may be promoted internally to accommodate the range of the other class.
The following examples demonstrate the promotion of
x
, which is an ImmediateInteger
object. The getClass
method is defined by
RootObject
, the root class from which all ScriptX
classes inherit, so it is available to all objects.
global x:2, y:3.5, z:123.456789, w:9876543210, a, b, c
getClass x
ImmediateInteger
getClass y
ImmediateFloat
getClass z
Float
getClass w
LargeInteger
a := x + y
5.5
getClass a
ImmediateFloat
b := x + z
125.456789
getClass b
Float
c := x + w
9876543212
getClass c
LargeInteger
The result may be demoted for efficiency, if there is no loss of range.
global p:3.23, q:4.23, resultObject
getClass p
ImmediateFloat
getClass q
ImmediateFloat
resultObject := p - q
1
getClass resultObject
ImmediateInteger
String addition concatenates its operands into a single string:
"this" + "that"
"thisthat"
"Once upon " + "a time"
String subtraction removes the first instance of the second string operand from the first:"Once upon a time"
"one two three" - "one"
" two three"
"banana" - "an"
The following code illustrates an easy way to print out the value of a variable. Note that the parentheses are necessary and that the integer x must be coerced to a"bana"
String
object in order to be added to another
string.x := 10
print ("x: "+ x as String)
"x: 10"
String subtraction can make stripping the extension away from a file name easy:
myFilename := "Answers.doc"
myPrefix := myFilename - ".doc"
"Answers"
This document is part of the ScriptX Language Guide, one of the volumes of the ScriptX Technical Reference Series. ScriptX is developed by the ScriptX Engineering Team at Apple Computer, successor to the Kaleida Engineering Team at Kaleida Labs, Inc.